/*     */ package com.zimbra.cs.util;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.db.DbConfig;
/*     */ import com.zimbra.cs.db.DbPool;
/*     */ import com.zimbra.cs.db.DbPool.DbConnection;
/*     */ import java.io.File;
/*     */ import java.sql.Timestamp;
/*     */ import java.util.Collection;
/*     */ import java.util.Iterator;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class Config
/*     */ {
/*     */   public static final String KEY_PURGE_LAST_MAILBOX_ID = "purge.lastMailboxId";
/*     */   public static final int D_LMTP_THREADS = 10;
/*     */   public static final int D_LMTP_BIND_PORT = 7025;
/*     */   public static final int D_IMAP_BIND_PORT = 143;
/*     */   public static final int D_IMAP_SSL_BIND_PORT = 993;
/*     */   public static final int D_POP3_BIND_PORT = 110;
/*     */   public static final int D_POP3_SSL_BIND_PORT = 995;
/*     */   public static final int D_MILTER_BIND_PORT = 7026;
/*     */   public static final int D_SMTP_TIMEOUT = 60;
/*     */   public static final int D_SMTP_PORT = 25;
/*     */   public static final long D_ZIMBRA_LAST_LOGON_TIMESTAMP_FREQUENCY = 604800000L;
/*     */   private static Map<String, DbConfig> mConfigMap;
/*     */   private static Timestamp mYoungest;
/*     */   
/*     */   private static void init(Timestamp ts)
/*     */     throws ServiceException
/*     */   {
/*  58 */     DbPool.DbConnection conn = null;
/*     */     try {
/*  60 */       conn = DbPool.getConnection();
/*  61 */       mConfigMap = DbConfig.getAll(conn, ts);
/*  62 */       for (it = mConfigMap.values().iterator(); it.hasNext();) {
/*  63 */         DbConfig c = (DbConfig)it.next();
/*  64 */         if (mYoungest == null) {
/*  65 */           mYoungest = c.getModified();
/*  66 */         } else if (c.getModified().after(mYoungest))
/*  67 */           mYoungest = c.getModified();
/*     */       }
/*     */     } finally {
/*     */       Iterator<DbConfig> it;
/*  71 */       if (conn != null)
/*  72 */         DbPool.quietClose(conn);
/*     */     }
/*     */   }
/*     */   
/*     */   private static synchronized void initConfig() {
/*  77 */     if (mConfigMap == null) {
/*     */       try {
/*  79 */         init(null);
/*     */       } catch (Exception e) {
/*  81 */         Zimbra.halt("Config initialization failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static synchronized String getString(String name, String defaultValue)
/*     */   {
/*  91 */     initConfig();
/*  92 */     DbConfig c = (DbConfig)mConfigMap.get(name);
/*  93 */     return c != null ? c.getValue() : defaultValue;
/*     */   }
/*     */   
/*     */   public static synchronized void setString(String name, String value) throws ServiceException
/*     */   {
/*  98 */     initConfig();
/*  99 */     DbPool.DbConnection conn = null;
/*     */     try {
/* 101 */       conn = DbPool.getConnection();
/* 102 */       DbConfig c = DbConfig.set(conn, name, value);
/* 103 */       mConfigMap.put(name, c);
/* 104 */       conn.commit();
/*     */     } finally {
/* 106 */       DbPool.quietClose(conn);
/*     */     }
/*     */   }
/*     */   
/*     */   public static synchronized int getInt(String name, int defaultValue) {
/* 111 */     initConfig();
/* 112 */     String value = getString(name, null);
/* 113 */     if (value == null) {
/* 114 */       return defaultValue;
/*     */     }
/* 116 */     int intValue = defaultValue;
/*     */     try {
/* 118 */       intValue = Integer.parseInt(value);
/*     */     } catch (NumberFormatException e) {
/* 120 */       ZimbraLog.misc.warn("Invalid integer value '%s' for config key '%s'.  Returning default value %d.", new Object[] { value, name, Integer.valueOf(intValue) });
/*     */     }
/*     */     
/* 123 */     return intValue;
/*     */   }
/*     */   
/*     */   public static synchronized void setInt(String name, int value) throws ServiceException
/*     */   {
/* 128 */     initConfig();
/* 129 */     setString(name, Integer.toString(value));
/*     */   }
/*     */   
/*     */   public static synchronized void setLong(String name, long value) throws ServiceException
/*     */   {
/* 134 */     initConfig();
/* 135 */     setString(name, Long.toString(value));
/*     */   }
/*     */   
/*     */   public static synchronized long getLong(String name, long defaultValue) {
/* 139 */     initConfig();
/* 140 */     String value = getString(name, null);
/* 141 */     if (value == null) {
/* 142 */       return defaultValue;
/*     */     }
/* 144 */     long longValue = defaultValue;
/*     */     try {
/* 146 */       longValue = Long.parseLong(value);
/*     */     } catch (NumberFormatException e) {
/* 148 */       ZimbraLog.misc.warn("Invalid long value '%s' for config key '%s'.  Returning default value %d.", new Object[] { value, name, Long.valueOf(longValue) });
/*     */     }
/*     */     
/* 151 */     return longValue;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static synchronized boolean getBoolean(String name, boolean defaultValue)
/*     */   {
/* 160 */     initConfig();
/* 161 */     String value = getString(name, null);
/* 162 */     return (value.equalsIgnoreCase("true")) || (value.equalsIgnoreCase("yes")) || (value.equals("1")) ? true : value == null ? defaultValue : false;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static File getPathRelativeToZimbraHome(String path)
/*     */   {
/* 174 */     char first = path.charAt(0);
/* 175 */     if ((first == File.separatorChar) || (first == '/')) {
/* 176 */       return new File(path);
/*     */     }
/* 178 */     String home = LC.zimbra_home.value();
/* 179 */     return new File(home, path);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/util/Config.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */